package org.example.struct.array;

/**
 * @author liyishan
 * @date 2024/1/2 09:33
 * @apiNote
 */

public class Test00168ConvertToTitle {

    public static String convertToTitle(int columnNumber) {
        StringBuilder res= new StringBuilder();
        while(columnNumber > 0){
            int temp = (columnNumber-1) % 26 +1 ;
            res.append((char)(temp + 'A' - 1));
            columnNumber = (columnNumber - temp) /26;
        }
        return res.reverse().toString();
    }

    public static String convertToTitle2(int columnNumber) {
        StringBuilder res= new StringBuilder();
        while(columnNumber != 0){
            columnNumber--;
            res.append((char)(columnNumber % 26 + 'A'));
            columnNumber /= 26;
        }
        return res.reverse().toString();
    }
}
